package com.gwtplatform.samples.tab.client.main;

import com.google.inject.Inject;

import com.guit.client.GuitPresenter;
import com.guit.client.View;
import com.guit.client.binder.GuitBinder;
import com.guit.client.binder.ViewField;
import com.gwtplatform.samples.tab.client.attacher.RootLayoutPanelAttacher;
import com.gwtplatform.samples.tab.client.main.MainPresenterImpl.MainPageBinder;

public class MainPresenterImpl extends GuitPresenter<MainPageBinder> implements MainPresenter {

    public static interface MainPageBinder extends GuitBinder<MainPresenterImpl> {
    }

    private final RootLayoutPanelAttacher attacher;

    @Inject
    public MainPresenterImpl(RootLayoutPanelAttacher attacher) {
        this.attacher = attacher;
    }
    
    @Override
    protected void initialize() {
        attacher.attach(getView());
    }
    
    @ViewField
    TabLayoutPanelI maintabpanel;
    
    @ViewField
    TabLayoutPanelI hometabpanel;
    
    @ViewField
    HasWidget info;
    
    @ViewField
    HasWidget news;
    
    @ViewField
    HasWidget aboutus;
    
    @ViewField
    HasWidget contact;
    
    @Override
    public void setHome(Home home, View v) {
        maintabpanel.selectTab(0);
        switch (home) {
            case INFO:
                info.setWidget(v);
                hometabpanel.selectTab(1);
                break;
            case NEWS:
                news.setWidget(v);
                hometabpanel.selectTab(0);
                break;
            default:
                throw new IllegalStateException();
        }
    }

    @Override
    public void setAboutUs(View v) {
        aboutus.setWidget(v);
        maintabpanel.selectTab(1);
    }

    @Override
    public void setContact(View v) {
        contact.setWidget(v);
        maintabpanel.selectTab(2);
    }
}
